import Compressor from "compressorjs";

export const compressorImage = (option, callBack) => {
  new Compressor(option.file, {
    quality: 0.5,
    //转换的类型，默认为 image/png
    convertTypes: ["image/jpeg"],
    //需要压缩的起始大小，默认5M, 5 * 1000 * 1000
    convertSize: 1000000,
    maxWidth: 1024,
    maxHeight: 780,
    success: result => {
      const blob = result instanceof Blob ? result : new Blob([result]);
      let newFile = new File([blob], option.file.name, { type: option.file.type });
      option.file = newFile;
      callBack();
    },
    error: error => {
      console.error(error.message);
    }
  });
};
